from pyutils import get_GET_ret, mytest_api, mytest_f_speed
import requests


local_headers = {
    'Content-Type': 'application/json',
    'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyOCwidXNlcm5hbWUiOiIxODUxMDc3OTEwMiIsImV4cCI6MTYyMjE4MjkyNSwiZW1haWwiOm51bGwsIm9yaWdfaWF0IjoxNjE2OTk4OTI1fQ.fC33BRfy9nPqVMmVchJQ9QKNOkD6zQIenT_6lYPvk2M',
}


class TestClass:
    def test_draw_local(self):
        # --------- 抽奖配置
        url_0 = 'http://127.0.0.1:8000/api/draw'
        print('--- url_0: ', url_0)
        resp = get_GET_ret(url_0, headers=local_headers)

        assert resp.get('status') == 200, "状态码返回错误!"

        print(f'*** resp: {resp}')

        res = resp.get('result')
        print('~~~ res: ', res)

    def test_draw_threading(self):
        url_0 = 'http://127.0.0.1:8000/api/draw'
        f = lambda : mytest_api(url_0, headers=local_headers)
        times = 30
        mytest_f_speed(f, times)
        print(f'测试抽奖次数: {times}次')

    def test_draw_search(self):
        url_0 = 'http://127.0.0.1:8000/api/draw/search/'
        mytest_api(url=url_0, headers=local_headers)

